<template>
  <el-dialog title="新建角色" width="50%" :before-close="handleClose">
    <el-form :model="roleForm" label-width="100px">
      <el-form-item label="角色名称">
        <el-input
          v-model="roleForm.name"
          placeholder="请输入角色名称"
        ></el-input>
      </el-form-item>
      <el-form-item label="角色描述">
        <el-input
          type="textarea"
          v-model="roleForm.description"
          placeholder="请输入角色描述"
        ></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="saveRole">创建</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref, reactive } from "vue";
import { modalControllers } from "@/stores/modalController.js";
import { storeToRefs } from "pinia";

const modalController = modalControllers();
const dialogVisible = storeToRefs(modalController.popups.newRoleModal);
const roleForm = reactive({
  name: "",
  description: "",
});

const handleClose = (done) => {
  done();
};

const saveRole = () => {
  console.log("New role data:", roleForm);
  // Implement save logic here
  dialogVisible.value = false;
};

const open = () => {
  dialogVisible.value = true;
  // Reset form on open
  roleForm.name = "";
  roleForm.description = "";
};

defineExpose({
  open,
});
</script>

<style scoped>
/* Add any specific styles for the modal here */
</style>
